<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="单据编号" prop="receiptcode">
      <el-input v-model="dataForm.receiptcode" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="房间类型" prop="typename">
      <el-input v-model="dataForm.typename" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="房间数量" prop="roomnum">
      <el-input v-model="dataForm.roomnum" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="应收金额" prop="totalshouldmoney">
      <el-input v-model="dataForm.totalshouldmoney" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="实收金额" prop="totalmoney">
      <el-input v-model="dataForm.totalmoney" placeholder=""></el-input>
    </el-form-item>
     <el-form-item label="订单状态" size="mini" prop="status">
      <el-radio-group v-model="dataForm.status">
        <el-radio :label="1">待入住</el-radio>
        <el-radio :label="2">已入住</el-radio>
        <el-radio :label="3">已完成</el-radio>
        <el-radio :label="4">已评价</el-radio>
        <el-radio :label="5">已取消</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="下单时间" prop="chargetime">
      <el-input v-model="dataForm.chargetime" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="用户姓名" prop="username">
      <el-input v-model="dataForm.username" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="入住时间" prop="starttime">
      <el-input v-model="dataForm.starttime" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="离开时间" prop="endtime">
      <el-input v-model="dataForm.endtime" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" :disabled="subable" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>
<script>
  export default {
    data () {
      return {
        subable: false,
        visible: false,
        dataForm: {
          id: 0,
          receiptcode: '',
          customerid: '',
          totalshouldmoney: '',
          totalmoney: '',
          chargetime: '',
          status: '',
          remark: '',
          roomnum: '',
          username: '',
          phone: '',
          starttime: '',
          endtime: '',
          roomtype: ''
        },
        dataRule: {}
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.subable = false
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/roomreceipt/roomreceipt/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.receiptcode = data.roomreceipt.receiptcode
                this.dataForm.customerid = data.roomreceipt.customerid
                this.dataForm.totalshouldmoney = data.roomreceipt.totalshouldmoney
                this.dataForm.totalmoney = data.roomreceipt.totalmoney
                this.dataForm.chargetime = data.roomreceipt.chargetime
                this.dataForm.status = data.roomreceipt.status
                this.dataForm.remark = data.roomreceipt.remark
                this.dataForm.roomnum = data.roomreceipt.roomnum
                this.dataForm.username = data.roomreceipt.username
                this.dataForm.phone = data.roomreceipt.phone
                this.dataForm.starttime = data.roomreceipt.starttime
                this.dataForm.endtime = data.roomreceipt.endtime
                this.dataForm.roomtype = data.roomreceipt.roomtype
                this.dataForm.typename = data.roomreceipt.typename
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.subable = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/roomreceipt/roomreceipt/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'receiptcode': this.dataForm.receiptcode,
                'customerid': this.dataForm.customerid,
                'totalshouldmoney': this.dataForm.totalshouldmoney,
                'totalmoney': this.dataForm.totalmoney,
                'chargetime': this.dataForm.chargetime,
                'status': this.dataForm.status,
                'remark': this.dataForm.remark,
                'roomnum': this.dataForm.roomnum,
                'username': this.dataForm.username,
                'phone': this.dataForm.phone,
                'roomtype': this.dataForm.roomtype
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1000,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          } else {
            this.subable = false
          }
        })
      }
    }
  }
</script>
